﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CMS.Model;

namespace CMS.Ulity
{
    public class CourseListComparer
    {
        /// <summary>
        /// Summary description for CourseListcomparer
        /// </summary>
        public class CourseListcomparer
        {
            public enum CompareType
            {
                CourseId,
                CourseName,
                StatusDisplay,
                TeacherName,
                LevelName,
                StudentNumber
            }
            public class CourseListComparer : IComparer<CourseList>
            {
                private CompareType _compareColumn;

                public CompareType CompareColumn
                {
                    get { return _compareColumn; }
                    set { _compareColumn = value; }
                }

                public CourseListComparer(CompareType t)
                {
                    this._compareColumn = t;

                }

                /// <summary>
                /// compare by different property
                /// </summary>
                /// <param name="x">CourseList x</param>
                /// <param name="y">CourseList y</param>
                /// <returns>int </returns>
                public int Compare(CourseList x, CourseList y)
                {
                    switch (this.CompareColumn)
                    {
                        case CompareType.CourseId:
                            return x.CourseId.CompareTo(y.CourseId);
                        case CompareType.CourseName:
                            return x.CourseName.CompareTo(y.CourseName);
                        case CompareType.StatusDisplay:
                            return x.CourseStatus.CompareTo(y.CourseStatus);
                        case CompareType.TeacherName:
                            return x.TeacherName.CompareTo(y.TeacherName);
                        case CompareType.LevelName:
                            return x.LevelName.CompareTo(y.LevelName);
                        case CompareType.StudentNumber:
                            return x.StudentNumber.CompareTo(y.StudentNumber);
                        default: return x.CourseId.CompareTo(y.CourseId);
                    }
                }
            }
        }
    }
}
